package com.aaa.stock.controller.api;

import com.aaa.entity.StockMedicines;
import com.aaa.entity.StockProducer;
import com.aaa.entity.StockProvider;
import com.aaa.stock.service.ProviderService;
import com.aaa.stock.vo.ProviderVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/stock/api/provider")
public class ApiProviderController {
@Autowired
    private ProviderService providerService;
//分页查询
@PostMapping("/list/{currentPage}/{pageSize}")

    public Result<IPage<StockProvider>> list1(
        @PathVariable Integer currentPage,
        @PathVariable Integer pageSize,
        @RequestBody ProviderVo providerVo
){
    System.out.println("=== === " + currentPage);
    System.out.println("=== === " + pageSize);
    System.out.println("ProviderVo = " + providerVo);
 return providerService.getByPage(currentPage,pageSize,providerVo);
}
    //添加，修改
    @PostMapping("addstu")
    public Result addstu(@RequestBody StockProvider stockProvider){
        if (Objects.nonNull(stockProvider.getProviderId())){
            stockProvider.setUpdateTime(LocalDateTime.now());
        }else {
            stockProvider.setCreateTime(LocalDateTime.now());
        }
        providerService.saveOrUpdate(stockProvider);
        return new Result (2000,"成功");
    }
    //删除
    @DeleteMapping("/{providerId}")
    public Result delStu( @PathVariable Integer providerId){
        providerService.removeById(providerId);
        return new Result(2000,"成功");
    }

    //批量删除
    @PostMapping("/del1")
    public Result delStu1( @RequestBody List<StockProvider> stockProviders){
        stockProviders.forEach((StockProvider stockProviders1)->{
            boolean b = providerService.removeById(stockProviders1.getProviderId());
        });
        return new Result(2000,"成功");
    }
    //查询全部
    @PostMapping("/list")
    public Result<List<StockProvider>>lsit(){
    return providerService.getAll();
    }



}
